package log_api

import (
	"gin_study_blog/common/http"
	"gin_study_blog/models"
	"gin_study_blog/plugins/log_stash"
	"gin_study_blog/service/helper"
	"github.com/gin-gonic/gin"
)

type LogRequest struct {
	models.PageInfo
	Level log_stash.Level `form:"level"`
}

func (LogApi) LogApiView(c *gin.Context) {
	var cr LogRequest
	err := c.ShouldBindQuery(&cr)

	log := log_stash.New(c.ClientIP(), c.GetHeader("token"))
	if err != nil {
		log.Waring(err.Error())
		http.FailWithCode(http.ParamsError, c)
		return
	}
	list, count, err := helper.CommonList(&log_stash.LogStashModel{Level: cr.Level}, helper.Option{
		PageInfo: cr.PageInfo,
		Debug:    true,
		Likes:    []string{"ip addr"},
	})
	http.IsOkWithList(list, count, c)
}
